package cn.shop.dys.fragment;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import cn.shop.dys.R;
import cn.shop.dys.activity.UserDetailsActivity;
import cn.shop.dys.adapter.CommonIndentAdapter;

/**
 * 基类fragment
 * Created by jian on 2016/4/8.
 */
public abstract class BaseFragment extends Fragment{
    private View rootView;
    public HttpUtils mHttpUtils;
    public Gson mGson;
    public Context mContext;
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        mContext = activity;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if(rootView==null){
          //  Log.d("test", "刷新2");
            mHttpUtils = new HttpUtils();
            mGson = new Gson();
            rootView = createView(inflater, container, savedInstanceState);
            ViewUtils.inject(this,rootView);
        }
        return rootView;
    }


   /* public UserInfo getUserInfo() {
        FragmentActivity activity = getActivity();
        if(activity instanceof UserDetailsActivity){
            return ((UserDetailsActivity) activity).getUserInfo();
        }
        return null;
    }*/

    public abstract View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState);
    public void setOnUserDetailsClickListener(OnUserDetailsClickListener listener){

    }
    /**
     * fragment之间的交互
     * 作者:孙建
     * created at 2016/4/25 15:56
     */
    public interface OnUserDetailsClickListener{
        void onClick(int index);
    }
    public void onBackPressed(){
        if(getActivity() instanceof UserDetailsActivity){
             ((UserDetailsActivity) getActivity()).disposeBackEvent();
        }
    }
}
